//
//  SISSMapAreaModel.m
//  SISSAPP
//
//  Created by 优房网 on 2017/5/31.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSMapAreaModel.h"

@implementation SISSMapAreaModel

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (instancetype)initWithDict:(NSDictionary *)dict{
    
    if (self = [super init]) {
        
        [self setValuesForKeysWithDictionary:dict];
    }
    
    return self;
}


+ (instancetype)mapAreaWithDict:(NSDictionary *)dict{
    
    return [[self alloc] initWithDict:dict];
}




#pragma mark - 加载数据
+ (NSArray<SISSMapAreaModel *>*)loadMapAreaData {
    
    //获取plist
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"mapArea" withExtension:@"plist"];
    
    //根据plist加载数组
    NSArray *dictArr = [NSArray arrayWithContentsOfURL:url];
    
    //定义一个保存模型类的数组
    NSMutableArray *arrayM = [NSMutableArray array];
    
    //循环遍历字典数组，把每个元素转为模型类对象
    for (NSDictionary *dict in dictArr) {
        
        SISSMapAreaModel *model = [SISSMapAreaModel mapAreaWithDict:dict];
        
        //再进行一次字典转模型
        NSMutableArray * tempArray = [NSMutableArray array];
        for (NSDictionary *areaDict in model.areas) {
            SISSMapAreaRegionModel *areaModel = [SISSMapAreaRegionModel mapAreaWithDict:areaDict];
            [tempArray addObject:areaModel];
        }
        model.areas = tempArray.copy;
        
        [arrayM addObject:model];
    }
    
    return arrayM.copy;
}

- (void)setAreas:(NSArray<SISSMapAreaRegionModel *> *)areas {
    _areas = areas;
    
    
}

@end
